using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlogSystem.Ability.Docking.UserApp;
using BlogSystem.Ability.Docking.UserApp.Dto;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace BlogSystem.Web.Controllers
{
    public class LoginController : BaseController
    {
        public IUserService UserService { get; set; }
        
        [HttpGet]
        public async Task<LoginSuccessDto> CheckLogin(string userName, string password)
        {
            var res = await UserService.CheckLogin(userName, password);
            //尝试获取缓存中的Token
            // var hasDic = Cache.TryGetValue("token", out Dictionary<string, LoginSuccessDto> dic);
            // if (!hasDic)
            // {
            //     dic = new Dictionary<string, LoginSuccessDto>();
            // }
            // dic.Add(res.Token, res);
            Cache.Set(res.Token, res, TimeSpan.FromMinutes(5));
            return res;
        }
    }
}